package com.example.mobile2021606127cxz0507;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity4 extends AppCompatActivity {

    private RadioGroup rg;
    private RadioButton rb1;
    private RadioButton rb2;
    private RadioButton rb3;
    private RadioButton rb4;
    private Button btnSubmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        initView();
    }

    private void initView() {
        rg = (RadioGroup) findViewById(R.id.rg);
        rb1 = (RadioButton) findViewById(R.id.rb1);
        rb2 = (RadioButton) findViewById(R.id.rb2);
        rb3 = (RadioButton) findViewById(R.id.rb3);
        rb4 = (RadioButton) findViewById(R.id.rb4);
        btnSubmit = (Button) findViewById(R.id.btn_submit);
    }

    public void submit(View view) {
        int rbId = rg.getCheckedRadioButtonId();
        if (rbId != -1) {
            RadioButton radioButton = findViewById(rbId);
            Intent intent = new Intent();
            intent.putExtra("supplier", radioButton.getText().toString());
            setResult(RESULT_OK, intent);
            finish();
        } else {
            new AlertDialog.Builder(MainActivity4.this)
                    .setMessage("请选择供应商")
                    .setPositiveButton("确定", null)
                    .create()
                    .show();

        }

    }
}